package com.qrcode.zxing;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.zxing.utils.ZxingClient;
import com.example.zxing.utils.ZxingResultBean;

import com.qrcode.scan.QRClient;
import com.qrcode.scan.QRCodeClient;
import com.qrcode.scan.QRCodeResultBean;
import com.qrcode.zbar.ZbarClient;
import com.qrcode.zbar.ZbarResultBean;

//import com.scancode.ocr.OcrClient;
//import com.scancode.ocr.OcrIDClient;


public class MainActivity extends AppCompatActivity {
    Button button;
    Button button2;
    Button button3;
    Button button4;
    Button button5;
    Button button6;
    TextView textView;
    private Activity mActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mActivity = this;
        button = findViewById(R.id.btn_default);
        button2 = findViewById(R.id.btn_default2);
        button3 = findViewById(R.id.btn_default3);
        button4 = findViewById(R.id.btn4);
        button5= findViewById(R.id.btn_default5);
        button6= findViewById(R.id.btn5);
        textView = findViewById(R.id.tv_content);


        button.setOnClickListener(v -> startZxing());

        button2.setOnClickListener(v -> startZbar());

        button3.setOnClickListener(v -> startOrc());

        button4.setOnClickListener(v -> startQRCodeScan());

        button5.setOnClickListener(v -> {
            startOrcID();
        });

        button6.setOnClickListener(v -> {
            startQR();
        });

    }


    private void startZxing() {
        ZxingClient.getClient().setResultListener(this, new ZxingClient.ScanResult() {
            @SuppressLint("LongLogTag")
            @Override
            public void back(ZxingResultBean result) {
                Log.e("MainActivity 收到的Zxing识别回调", result.getTag() + result.getResult());
                textView.setText("内容:" + result.getResult());
            }
        });

        ZxingClient.getClient().setDefault()
                .setDebug(true)
                .setToOsBar(true)
                .setScanLineColor(ContextCompat.getColor(mActivity, R.color.teal_200))
                .setScanBorderColor(ContextCompat.getColor(mActivity, R.color.white))
                .setScanTipTextColor(ContextCompat.getColor(mActivity, R.color.Red))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.purple_200))
                .setScanTipText("我是测试提示")
                .setOpenPhoto(true)
                .startZxing(mActivity);
    }


    private void startZbar() {
        ZbarClient.getClient().setZbarResultListener(this, new ZbarClient.ScanResult() {
            @SuppressLint("LongLogTag")
            @Override
            public void back(ZbarResultBean result) {
                Log.e("MainActivity 收到的Zbar识别回调", result.getTag() + result.getResult());
                textView.setText("内容:" + result.getResult());
            }
        });

        ZbarClient.getClient().setDefault()
                .setDebug(true)
                .setToOsBar(true)
                .setScanLineColor(ContextCompat.getColor(mActivity, R.color.teal_200))
                .setScanBorderColor(ContextCompat.getColor(mActivity, R.color.white))
                .setScanTipTextColor(ContextCompat.getColor(mActivity, R.color.Red))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.purple_200))
                .setScanTipText("我是测试提示")
                .setOpenPhoto(true)
                .startZbar(mActivity);
    }


    private void startOrc() {
      /*  OcrClient.getClient().setResultListener(this, result -> {
            Log.e("MainActivity 收到的Ocr识别回调", result.getTag() + result.getResult());
            textView.setText("内容:" + result.getResult());
        });

        OcrClient.getClient().setDefault()
                .setDebug(true)
                .setToOsBar(true)
                .setBarBgColor(ContextCompat.getColor(mActivity, R.color.teal_700))
                .setScanLineColor(ContextCompat.getColor(mActivity, R.color.Blue))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.Blue))
                .setOpenLight(true)
                .startOcr(mActivity);*/
    }


    private void startQRCodeScan() {
        QRCodeClient.getClient().setScanResultListener(this, new QRCodeClient.ScanResult() {
            @SuppressLint("LongLogTag")
            @Override
            public void back(QRCodeResultBean result) {
                Log.e("MainActivity 收到的Scan识别回调", result.getTag() + result.getResult());
                textView.setText("内容:" + result.getResult());
            }
        });


        QRCodeClient.getClient().setDefault()
                .setDebug(true)
                .setToOsBar(true)
                .setShowBackText(true)
                .setShowRightPower(true)
                .setScanLineColor(ContextCompat.getColor(mActivity, R.color.teal_200))
                .setScanBorderColor(ContextCompat.getColor(mActivity, R.color.white))
                .setScanTipTextColor(ContextCompat.getColor(mActivity, R.color.Red))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.purple_200))
                .setScanTipText("我是测试提示")
                .setOpenPhoto(true)
                .setBtmBtnHint(true,"查看巡检点位地图")
                .startScan(mActivity);
    }


    private void startOrcID() {
       /* OcrIDClient.getClient().setResultListener(this, result -> {
            Log.e("MainActivity 收到的Ocr识别回调", result.getTag() + result.getResult());
            textView.setText("内容:" + result.getResult());
        });

        OcrIDClient.getClient().setDefault()
                .setDebug(true)
                .setToOsBar(true)
                .setBarBgColor(ContextCompat.getColor(mActivity, R.color.teal_700))
                .setScanLineColor(ContextCompat.getColor(mActivity, R.color.Blue))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.Blue))
                .setOpenLight(true)
                .startOcr(mActivity);*/
    }


    private void startQR() {
        QRClient.getClient().setDefault();

        QRClient.getClient().setInspectionOnClickListen(new QRClient.inspectionOnClickListen() {
            @Override
            public void onClick() {
                Log.e("MainActivity 收到的QR回调","点击了巡检");
            }
        });

        QRClient.getClient().setPhotoOnClickListen(new QRClient.photoOnClickListen() {
            @Override
            public void onClick(Activity activity) {
                Log.e("MainActivity 收到的QR回调","点击了相册"+activity.getClass().getName());
            }
        });

        QRClient.getClient().setTakePhotoResult(new QRClient.PhotoResult() {
            @Override
            public void back(String path) {
                Log.e("MainActivity 收到的QR回调","path:"+ path);
            }
        });

        QRClient.getClient()
                .setDebug(true)
                .setToOsBar(true)
                .setStrWaterMark("这个是测试水印文字")
                .setShowRightPower(true)
                .setScanBorderColor(ContextCompat.getColor(mActivity, R.color.white))
                .setScanTipTextColor(ContextCompat.getColor(mActivity, R.color.Red))
                .setScanCornerColor(ContextCompat.getColor(mActivity, R.color.purple_200))
                .setScanTipText("请把二维码放入框内")
                .setOpenPhoto(true)
                .startQR(mActivity);
    }
}